<#if roles.moneyOut>
<div class="row plan-payout">
	<div class="col-md-12">
		<div class="panel panel-primary">
			<div class="panel-heading">
				<h3 class="panel-title">
					<i class="icon-signout icon-large"></i>
					7日内待付款任务
				</h3>
			</div>
			<#if payoutPlan??>
			<table class="table table-hover">
				<tr>
					<th class="text-center" width="55">操作</th>
					<th class="text-center" width="70">状态</th>
					<th class="text-center" width="180">付款金额（元）</th>
					<th class="text-center" width="115">付款时间</th>
					<th class="text-center">付款事项</th>
					<th class="text-center" width="100">创建人</th>
					<th class="text-center" width="225">合同编号</th>
					<th class="text-center">合同名称</th>
				</tr>
				<#list payoutPlan as p>
				<!--  -->
				<#assign url=((p.contract.mainContract)?string('contract','sub-contract'))!'contract'>
				<tr class="${((p.payout)?string('text-deleted text-danger',''))}" style="cursor: pointer;" data-url="${url}" data-cid="${p.contract.id}">
					<td class="text-center">
						<#if p.payout?? && !p.payout>
						<div class="btn btn-danger btn-xs payout-by-plan" data-id="${p.contract.id}" data-plan-id="${p.id}">付款</div>
						</#if>
					</td>
					<td class="text-center cell-for-open">${((p.payout)?string('已付款','待付'))}</td>
					<td class="text-center cell-for-open">${p.total?string('currency')}</td>
					<td class="text-center cell-for-open">${(p.payoutTime?string('yyyy-MM-dd'))!'-'}</td>
					<td class="text-center cell-for-open">${p.reason}</td>
					<td class="text-center cell-for-open">${p.creater.name}</td>
					<td class="text-center cell-for-open">${p.contract.no}</td>
					<td class="text-center cell-for-open">${p.contract.name}</td>
				</tr>
				</#list>
			</table>

			<script type="text/javascript">
				$(function() {
					// 打开合同
					$('.plan-payout').on('click', '.cell-for-open', function() {
						var $this = $(this);
						var tr = $this.parent('tr');
						var url = tr.data('url');
						var cid = tr.data('cid');

						window.open('${request.contextPath}/' + url + '/view/' + cid, '_blank');
					});

					// 通过付款计划付款
					$('.plan-payout').on('click', '.btn.payout-by-plan', function() {
						var $this = $(this);
						var id = $this.data('id'); // 合同
						var planId = $this.data('plan-id'); // 付款计划
						var fp = true // 发票已开

						var refresh = false;

						$.ajax({
							url : '${request.contextPath}/contract/payout-money-by-plan',
							type : 'post',
							async : false,
							data : {
								id : id,
								planId : planId,
								faPiao : fp
							},
							dataType : 'json',
							success : function(result, textStatus, jqXHR) {
								if (!result || !result.success) {
									alert(result.msg || '付款失败！');
									return false;
								}

								refresh = true;
							},
							error : function(jqXHR, textStatus, errorThrown) {
								alert('付款失败！\n\n' + errorThrown);
							}
						});

						if (refresh)
							$.suredy.loadContent('${request.contextPath}/front-page');
					});
				});
			</script>
			<#else>
			<div class="panel-body text-danger">暂无7日内计划！</div>
			</#if>
		</div>
	</div>
</div>
</#if>
